package com.hippoDocker.security.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName PageConfig
 * @Description TODO Mybatis配置
 * @Author tangxl
 * @Date 2022/8/2 9:49
 **/
@Configuration
public class MybatisPlusConfig {

    /**
     * 3.4.0以前版本
     * @return
     */
//    @Bean
//    public PaginationInnerInterceptor paginationInnerInterceptor(){
//        return new PaginationInnerInterceptor();
//    }

    /**
     * mybatisPlus多插件配置
     * MybatisPlus分页查询拦截器(分页插件)+数据版本(@Version)拦截(乐观锁插件)
     * 3.4.0以后版本
     * @return
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor()); //分页查询拦截
        mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());//乐观锁数据版本拦截--字段上加@Version注解
        return mybatisPlusInterceptor;
    }
}
